package com.data241210.SpringbootDemo.controller;

import com.data241210.SpringbootDemo.config.RedisConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;

/**
 * 控制器
 */
@Controller
public class HelloController {

    //依赖注入
    @Autowired
    private RedisConfig redisConfig;

    @ResponseBody
    @RequestMapping("/hello")
    public String hello(){
        return "hello";
    }

    @RequestMapping("/index")
    public String index(Model model){

        String msg="hello,Tangshan!";
        model.addAttribute("msg",msg);
        //传递单个数据
        int age=18;
        model.addAttribute("age",age);
        //传递数组
        ArrayList<String> arrayList=new ArrayList<>();
        arrayList.add("石家庄");
        arrayList.add("廊坊");
        arrayList.add("保定");
        arrayList.add("哈尔滨");
        arrayList.add("石家庄");
        arrayList.add("热部署");
        model.addAttribute("lists",arrayList);
        return "index";
    }

    @RequestMapping("/redis")
    @ResponseBody
    public RedisConfig redis(){
        return redisConfig;
    }
}
